package com.icongyou.enterprise.talent_analysis.entity.template;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class TemplateMetricMapping implements Cloneable {
    @NotBlank(message = "metricKey 不能为空")
    private String metricKey;

    @Positive(message = "metric 权重需为正数")
    private Double weight;

    private String normalization; // direct/ratio/minmax 等

    private Map<String, Object> params;

    private String source;

    private String sql;

    @Override
    public TemplateMetricMapping clone() {
        try {
            TemplateMetricMapping copy = (TemplateMetricMapping) super.clone();
            if (this.params != null) {
                copy.setParams(new HashMap<>(this.params));
            }
            return copy;
        } catch (CloneNotSupportedException e) {
            TemplateMetricMapping copy = new TemplateMetricMapping();
            copy.setMetricKey(this.metricKey);
            copy.setWeight(this.weight);
            copy.setNormalization(this.normalization);
            copy.setParams(this.params == null ? null : new HashMap<>(this.params));
            copy.setSource(this.source);
            copy.setSql(this.sql);
            return copy;
        }
    }
}
